package actions;

import java.util.ArrayList;
import java.util.Map;

import javax.ejb.EJB;

import beans.BookManager;
import beans.BookManagerBean;
import beans.SearchBean;
import beans.SearchManager;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import entities.Item;

public class LoadBooksAction extends ActionSupport {

	private ArrayList<Item> resultList;

	@EJB
	private SearchManager searchManager;

	public String execute() {

		searchManager = new SearchBean();
		Map session = ActionContext.getContext().getSession();
		Integer id = (Integer) session.get("userId");
		if (id == null) {
			this.addActionError("User ID is null");
			return ERROR;
		}

		resultList = searchManager.getItems(id.intValue());

		return SUCCESS;
	}

	public ArrayList<Item> getResultList() {
		return resultList;
	}

	public void setResultList(ArrayList<Item> resultList) {
		this.resultList = resultList;
	}

}
